<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery-validate/1.11.1/jquery.validate.min.js"></script>
    <script type="text/javascript"
            src="https://cdn.bootcss.com/jquery-validate/1.11.1/localization/messages_zh.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/layer/3.1.0/layer.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/blueimp-md5/2.10.0/js/md5.min.js"></script>
    <script type="text/javascript" src="./js/common-min.js"></script>
    <style>
        form {
            position: absolute;
            width: 50%;
            height: 30%;
            text-align: center;
            top: 50%;
            left: 50%;
            margin-top: -10%;
            margin-left: -20%;
        }

        body {
            background-image: url(./img/bg.jpg);
            background-repeat: no-repeat;
            background-size: cover;
        }
    </style>
</head>
<body>

<form name="loginFrom" id="loginFrom" method="post">
    <h2 style="text-align: center;margin-bottom: 20px">用户登录</h2>
    <div class="form-group">
        <div class="row">
            <label class="from-label col-md-4">请输入手机号码</label>
            <div class="col-md-5">
                <input id="mobile" name="mobile" class="form-control" type="text" placeholder="手机号码" required="true"
                       minlength="11" maxlength="11"/>
            </div>
            <div class="dol-md-1"></div>
        </div>
    </div>
    <div class="from-group">
        <div class="row">
            <label class="from-label col-md-4">请输入密码</label>
            <div class="col-md-5">
                <input id="password" name="password" class="form-control" type="password" placeholder="密码"
                       required="true" minlength="6" maxlength="16"/>
            </div>
        </div>
    </div>

    <div class="row" style="    margin-top: 8%;margin-left: 8%;">
        <div class="col-md-5">
            <button style="width: 70%" class="btn btn-primary btn-block" type="reset" onclick="reset()">重置</button>
        </div>
        <div class="col-md-5">
            <button style="width: 70%" class="btn btn-primary btn-block" type="submit" onclick="login()">登录</button>
        </div>
    </div>
</form>

</body>
<script>
    function login() {
        $("#loginFrom").validate({
            submitHandler: function (form) {
                doLogin();
            }
        });
    }

    function doLogin() {
        g_showLoading();

        var pass = $('#password').val();
        var password = md5To(pass);
        $.ajax({
            url: "/login/do_login",
            type: "POST",
            data: {
                mobile: $('#mobile').val(),
                password: password
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 0) {
                    layer.msg("成功");
                    window.location.href = "./goods_list.html";
                } else {
                    layer.msg(data.msg);
                }
                console.log(data);
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
</script>
</html>